package com.xiaohei.process.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiaohei.model.process.ProcessTemplate;
import com.xiaohei.model.process.ProcessType;
import com.xiaohei.process.mapper.ProcessTypeMapper;
import com.xiaohei.process.service.ProcessTemplateService;
import com.xiaohei.process.service.ProcessTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class ProcessTypeServiceImpl extends ServiceImpl<ProcessTypeMapper, ProcessType> implements ProcessTypeService {

    @Autowired
    private ProcessTemplateService processTemplateService;

    //查询所有分类和每个分类对应的审批模版
    @Override
    public List<ProcessType> getProcessType() {
        //1.获取所有分类信息
        List<ProcessType> processTypeList = baseMapper.selectList(null);
        //2.遍历返回所有审批分类list结合
        for(ProcessType processType : processTypeList){
            //3. 得到每个审批分类，根据审批分类id查询对应审批模版
            Long id = processType.getId();

            LambdaQueryWrapper<ProcessTemplate> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(ProcessTemplate::getProcessTypeId,id);
            List<ProcessTemplate> processTemplateList = processTemplateService.list();
            //4. 根据审批分类id查询对应审批模版数据（list）封装到每个审批对线里面
            processType.setProcessTemplateList(processTemplateList);
        }

        return processTypeList;
    }
}